<template>
  <div class="jenkins-builds-audit-container">
    <!-- 星空背景 -->
    <div class="starry-background"></div>

    <!-- 透明玻璃容器 -->
    <div class="glass-container">
      <div class="page-header">
        <h2 class="page-title">
          <i class="fa fa-cogs"></i>
          Jenkins构建历史
        </h2>
      </div>

      <!-- 工具栏：操作按钮 + 搜索过滤 -->
      <div class="builds-filters glass-effect">
        <div class="toolbar-left">
          <button class="glass-button" @click="refreshBuilds">
            <i class="fa fa-refresh"></i>
            刷新
          </button>
          <button class="glass-button" @click="exportBuilds">
            <i class="fa fa-download"></i>
            导出
          </button>
        </div>

        <div class="toolbar-right">
          <div class="search-group">
            <input
              v-model="searchText"
              type="text"
              class="glass-input"
              placeholder="搜索任务名称、构建号..."
            />
          </div>

          <div class="filter-group">
            <select v-model="selectedProject" class="glass-select">
              <option value="">所有项目</option>
              <option v-for="project in projects" :key="project.id" :value="project.id">
                {{ project.name }}
              </option>
            </select>
          </div>

          <div class="filter-group">
            <select v-model="selectedEnvironment" class="glass-select">
              <option value="">所有环境</option>
              <option v-for="env in environments" :key="env.id" :value="env.id">
                {{ env.name }}
              </option>
            </select>
          </div>

          <div class="filter-group">
            <select v-model="selectedStatus" class="glass-select">
              <option value="">所有状态</option>
              <option value="SUCCESS">成功</option>
              <option value="FAILURE">失败</option>
              <option value="UNSTABLE">不稳定</option>
              <option value="ABORTED">已中止</option>
            </select>
          </div>

          <div class="filter-group">
            <select v-model="selectedJobType" class="glass-select">
              <option value="">所有类型</option>
              <option value="freestyle">Freestyle</option>
              <option value="maven">Maven</option>
              <option value="pipeline">Pipeline</option>
            </select>
          </div>

          <div class="filter-group">
            <input
              v-model="dateRange.start"
              type="date"
              class="glass-input"
              placeholder="开始日期"
            />
          </div>

          <div class="filter-group">
            <input
              v-model="dateRange.end"
              type="date"
              class="glass-input"
              placeholder="结束日期"
            />
          </div>
        </div>
      </div>

      <!-- 构建历史表格 -->
      <div class="builds-table">
        <div class="table-header">
          <div class="header-cell">构建信息</div>
          <div class="header-cell">任务信息</div>
          <div class="header-cell">触发用户</div>
          <div class="header-cell">项目环境</div>
          <div class="header-cell">构建状态</div>
          <div class="header-cell">持续时间</div>
          <div class="header-cell">操作</div>
        </div>

        <div class="table-body">
          <div
            v-for="build in filteredBuilds"
            :key="build.id"
            class="table-row"
            :class="getBuildRowClass(build.status)"
          >
            <div class="table-cell">
              <div class="build-info">
                <div class="build-number">#{{ build.build_number }}</div>
                <div class="build-time">{{ formatDateTime(build.start_time) }}</div>
                <div class="git-info" v-if="build.git_commit">
                  <span class="git-commit">{{ build.git_commit.substring(0, 8) }}</span>
                  <span class="git-branch">{{ build.git_branch }}</span>
                </div>
              </div>
            </div>

            <div class="table-cell">
              <div class="job-info">
                <div class="job-name">{{ build.job?.name }}</div>
                <div class="job-server">{{ build.job?.jenkins_server?.name }}</div>
                <span
                  class="job-type-badge"
                  :class="getJobTypeClass(build.job?.job_type)"
                >
                  {{ getJobTypeText(build.job?.job_type) }}
                </span>
              </div>
            </div>

            <div class="table-cell">
              <div class="user-info">
                <div class="username">{{ build.started_by?.username || '系统触发' }}</div>
                <div class="user-name">{{ build.started_by?.first_name }} {{ build.started_by?.last_name }}</div>
              </div>
            </div>

            <div class="table-cell">
              <div class="project-env-info">
                <div class="project-name">{{ build.job?.project?.name || '-' }}</div>
                <span
                  v-if="build.job?.environment"
                  class="env-badge"
                  :class="getEnvClass(build.job?.environment?.code)"
                >
                  {{ build.job?.environment?.name }}
                </span>
              </div>
            </div>

            <div class="table-cell">
              <span
                class="status-badge"
                :class="getStatusClass(build.status)"
              >
                <i :class="getStatusIcon(build.status)"></i>
                {{ getStatusText(build.status) }}
              </span>
            </div>

            <div class="table-cell">
              <div class="duration-info">
                <div class="duration">{{ formatDuration(build.duration) }}</div>
                <div class="progress" v-if="build.status === 'BUILDING'">
                  <div class="progress-bar"></div>
                </div>
              </div>
            </div>

            <div class="table-cell">
              <div class="action-buttons">
                <button class="glass-button small" @click="viewLogs(build)">
                  <i class="fa fa-file-text"></i>
                  日志
                </button>
                <button class="glass-button small" @click="viewDetails(build)">
                  <i class="fa fa-eye"></i>
                  详情
                </button>
                <button
                  v-if="build.status !== 'BUILDING'"
                  class="glass-button small"
                  @click="rebuildJob(build)"
                >
                  <i class="fa fa-repeat"></i>
                  重建
                </button>
                <button class="glass-button small" @click="openJenkins(build)">
                  <i class="fa fa-external-link"></i>
                  Jenkins
                </button>
              </div>
            </div>
          </div>
        </div>

        <!-- 空状态 -->
        <div v-if="filteredBuilds.length === 0" class="empty-state">
          <i class="fa fa-cogs empty-icon"></i>
          <h3>暂无构建记录</h3>
          <p>在选定的条件下没有找到相关的Jenkins构建记录</p>
        </div>
      </div>

      <!-- 分页 -->
      <div v-if="pagination.total > 0" class="pagination">
        <div class="pagination-info">
          共 {{ pagination.total }} 条记录，第 {{ pagination.current }} / {{ Math.ceil(pagination.total / pagination.pageSize) }} 页
        </div>
        <div class="pagination-controls">
          <button
            class="glass-button small"
            @click="changePage(pagination.current - 1)"
            :disabled="pagination.current <= 1"
          >
            <i class="fa fa-chevron-left"></i>
            上一页
          </button>
          <button
            class="glass-button small"
            @click="changePage(pagination.current + 1)"
            :disabled="pagination.current >= Math.ceil(pagination.total / pagination.pageSize)"
          >
            下一页
            <i class="fa fa-chevron-right"></i>
          </button>
        </div>
      </div>
    </div>

    <!-- 构建日志模态框 -->
    <div v-if="logModalVisible" class="modal-overlay" @click="closeLogModal">
      <div class="modal-content glass-container log-modal" @click.stop>
        <div class="modal-header">
          <h3>构建日志 - {{ selectedBuild?.job?.name }} #{{ selectedBuild?.build_number }}</h3>
          <button class="close-btn" @click="closeLogModal">
            <i class="fa fa-times"></i>
          </button>
        </div>

        <div class="log-content">
          <div class="log-toolbar">
            <button class="glass-button small" @click="refreshLogs">
              <i class="fa fa-refresh"></i>
              刷新
            </button>
            <button class="glass-button small" @click="downloadLogs">
              <i class="fa fa-download"></i>
              下载
            </button>
            <button class="glass-button small" @click="toggleAutoScroll">
              <i class="fa fa-arrow-down"></i>
              {{ autoScroll ? '停止' : '开启' }}自动滚动
            </button>
          </div>

          <div class="log-viewer" ref="logViewer">
            <div
              v-for="(line, index) in buildLogs"
              :key="index"
              class="log-line"
              :class="getLogLineClass(line)"
            >
              <span class="line-number">{{ index + 1 }}</span>
              <span class="line-content">{{ line.content }}</span>
            </div>

            <div v-if="buildLogs.length === 0" class="log-empty">
              <i class="fa fa-spinner fa-spin"></i>
              加载日志中...
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 构建详情模态框 -->
    <div v-if="detailModalVisible" class="modal-overlay" @click="closeDetailModal">
      <div class="modal-content glass-container" @click.stop>
        <div class="modal-header">
          <h3>构建详情</h3>
          <button class="close-btn" @click="closeDetailModal">
            <i class="fa fa-times"></i>
          </button>
        </div>

        <div class="build-detail-content">
          <div class="detail-section">
            <h4>基本信息</h4>
            <div class="detail-grid">
              <div class="detail-item">
                <span class="label">构建号:</span>
                <span class="value">#{{ selectedBuild?.build_number }}</span>
              </div>
              <div class="detail-item">
                <span class="label">任务名称:</span>
                <span class="value">{{ selectedBuild?.job?.name }}</span>
              </div>
              <div class="detail-item">
                <span class="label">构建状态:</span>
                <span class="value">{{ getStatusText(selectedBuild?.status) }}</span>
              </div>
              <div class="detail-item">
                <span class="label">触发用户:</span>
                <span class="value">{{ selectedBuild?.started_by?.username || '系统触发' }}</span>
              </div>
              <div class="detail-item">
                <span class="label">开始时间:</span>
                <span class="value">{{ formatDateTime(selectedBuild?.start_time) }}</span>
              </div>
              <div class="detail-item">
                <span class="label">持续时间:</span>
                <span class="value">{{ formatDuration(selectedBuild?.duration) }}</span>
              </div>
            </div>
          </div>

          <div class="detail-section" v-if="selectedBuild?.git_commit">
            <h4>Git信息</h4>
            <div class="detail-grid">
              <div class="detail-item">
                <span class="label">提交ID:</span>
                <span class="value">{{ selectedBuild.git_commit }}</span>
              </div>
              <div class="detail-item">
                <span class="label">分支:</span>
                <span class="value">{{ selectedBuild.git_branch }}</span>
              </div>
            </div>
          </div>

          <div class="detail-section" v-if="selectedBuild?.build_parameters">
            <h4>构建参数</h4>
            <pre class="detail-json">{{ JSON.stringify(selectedBuild.build_parameters, null, 2) }}</pre>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed, nextTick, onMounted, ref } from 'vue'

// 响应式数据
const builds = ref([])
const projects = ref([])
const environments = ref([])
const searchText = ref('')
const selectedProject = ref('')
const selectedEnvironment = ref('')
const selectedStatus = ref('')
const selectedJobType = ref('')
const dateRange = ref({
  start: '',
  end: ''
})
const logModalVisible = ref(false)
const detailModalVisible = ref(false)
const selectedBuild = ref(null)
const buildLogs = ref([])
const autoScroll = ref(true)
const logViewer = ref(null)
const pagination = ref({
  current: 1,
  pageSize: 20,
  total: 0
})

// 计算属性
const filteredBuilds = computed(() => {
  let filtered = builds.value

  // 搜索过滤
  if (searchText.value) {
    const search = searchText.value.toLowerCase()
    filtered = filtered.filter(build =>
      build.job?.name.toLowerCase().includes(search) ||
      build.build_number.toString().includes(search)
    )
  }

  // 项目过滤
  if (selectedProject.value) {
    filtered = filtered.filter(build => build.job?.project?.id == selectedProject.value)
  }

  // 环境过滤
  if (selectedEnvironment.value) {
    filtered = filtered.filter(build => build.job?.environment?.id == selectedEnvironment.value)
  }

  // 状态过滤
  if (selectedStatus.value) {
    filtered = filtered.filter(build => build.status === selectedStatus.value)
  }

  // 任务类型过滤
  if (selectedJobType.value) {
    filtered = filtered.filter(build => build.job?.job_type === selectedJobType.value)
  }

  // 日期范围过滤
  if (dateRange.value.start) {
    filtered = filtered.filter(build =>
      new Date(build.start_time) >= new Date(dateRange.value.start)
    )
  }

  if (dateRange.value.end) {
    filtered = filtered.filter(build =>
      new Date(build.start_time) <= new Date(dateRange.value.end + ' 23:59:59')
    )
  }

  return filtered.sort((a, b) => new Date(b.start_time).getTime() - new Date(a.start_time).getTime())
})

// 方法
const refreshBuilds = async () => {
  await loadBuilds()
}

const exportBuilds = () => {
  // TODO: 实现导出功能
  console.log('导出Jenkins构建历史')
}

const viewLogs = async (build: any) => {
  selectedBuild.value = build
  logModalVisible.value = true
  await loadBuildLogs(build)
}

const viewDetails = (build: any) => {
  selectedBuild.value = build
  detailModalVisible.value = true
}

const rebuildJob = async (build: any) => {
  if (confirm(`确定要重新构建 "${build.job?.name}" 吗？`)) {
    try {
      // TODO: 调用API重新构建
      console.log('重新构建:', build.id)
      alert('构建已触发！')
    } catch (error) {
      console.error('重新构建失败:', error)
    }
  }
}

const openJenkins = (build: any) => {
  // TODO: 打开Jenkins链接
  console.log('打开Jenkins:', build)
}

const closeLogModal = () => {
  logModalVisible.value = false
  selectedBuild.value = null
  buildLogs.value = []
}

const closeDetailModal = () => {
  detailModalVisible.value = false
  selectedBuild.value = null
}

const refreshLogs = async () => {
  if (selectedBuild.value) {
    await loadBuildLogs(selectedBuild.value)
  }
}

const downloadLogs = () => {
  // TODO: 实现日志下载
  console.log('下载构建日志')
}

const toggleAutoScroll = () => {
  autoScroll.value = !autoScroll.value
}

const changePage = (page: number) => {
  pagination.value.current = page
  loadBuilds()
}

const getBuildRowClass = (status: string) => {
  const statusClasses = {
    'SUCCESS': 'row-success',
    'FAILURE': 'row-failure',
    'UNSTABLE': 'row-unstable',
    'ABORTED': 'row-aborted',
    'BUILDING': 'row-building'
  }
  return statusClasses[status] || 'row-unknown'
}

const getJobTypeClass = (jobType: string) => {
  const typeClasses = {
    'freestyle': 'type-freestyle',
    'maven': 'type-maven',
    'pipeline': 'type-pipeline'
  }
  return typeClasses[jobType] || 'type-default'
}

const getJobTypeText = (jobType: string) => {
  const typeTexts = {
    'freestyle': 'Freestyle',
    'maven': 'Maven',
    'pipeline': 'Pipeline'
  }
  return typeTexts[jobType] || jobType
}

const getEnvClass = (envCode: string) => {
  const envClasses = {
    'dev': 'env-dev',
    'test': 'env-test',
    'uat': 'env-uat',
    'prod': 'env-prod'
  }
  return envClasses[envCode] || 'env-default'
}

const getStatusClass = (status: string) => {
  const statusClasses = {
    'SUCCESS': 'status-success',
    'FAILURE': 'status-failure',
    'UNSTABLE': 'status-unstable',
    'ABORTED': 'status-aborted',
    'BUILDING': 'status-building'
  }
  return statusClasses[status] || 'status-unknown'
}

const getStatusIcon = (status: string) => {
  const statusIcons = {
    'SUCCESS': 'fa fa-check-circle',
    'FAILURE': 'fa fa-times-circle',
    'UNSTABLE': 'fa fa-exclamation-triangle',
    'ABORTED': 'fa fa-stop-circle',
    'BUILDING': 'fa fa-spinner fa-spin'
  }
  return statusIcons[status] || 'fa fa-question-circle'
}

const getStatusText = (status: string) => {
  const statusTexts = {
    'SUCCESS': '成功',
    'FAILURE': '失败',
    'UNSTABLE': '不稳定',
    'ABORTED': '已中止',
    'BUILDING': '构建中'
  }
  return statusTexts[status] || '未知'
}

const getLogLineClass = (line: any) => {
  if (line.level === 'ERROR') return 'log-error'
  if (line.level === 'WARN') return 'log-warn'
  if (line.level === 'INFO') return 'log-info'
  return 'log-default'
}

const formatDateTime = (dateString: string) => {
  if (!dateString) return '-'
  return new Date(dateString).toLocaleString('zh-CN')
}

const formatDuration = (duration: number) => {
  if (!duration) return '-'
  const seconds = Math.floor(duration / 1000)
  const minutes = Math.floor(seconds / 60)
  const hours = Math.floor(minutes / 60)

  if (hours > 0) {
    return `${hours}小时${minutes % 60}分钟`
  } else if (minutes > 0) {
    return `${minutes}分钟${seconds % 60}秒`
  } else {
    return `${seconds}秒`
  }
}

const loadBuilds = async () => {
  try {
    // TODO: 调用API获取Jenkins构建历史
    console.log('加载Jenkins构建历史')
    // 模拟数据
    builds.value = [
      {
        id: 1,
        build_number: 123,
        status: 'SUCCESS',
        start_time: '2024-01-01T12:00:00Z',
        duration: 120000,
        git_commit: 'abc123def456',
        git_branch: 'main',
        job: {
          id: 1,
          name: 'frontend-build-dev',
          job_type: 'freestyle',
          project: { id: 1, name: '电商系统' },
          environment: { id: 1, name: '开发环境', code: 'dev' },
          jenkins_server: { id: 1, name: '开发环境Jenkins' }
        },
        started_by: { id: 1, username: 'developer1', first_name: '张', last_name: '三' },
        build_parameters: {
          BRANCH: 'main',
          ENVIRONMENT: 'dev'
        }
      }
    ]

    pagination.value.total = builds.value.length
  } catch (error) {
    console.error('加载Jenkins构建历史失败:', error)
  }
}

const loadBuildLogs = async (build: any) => {
  try {
    // TODO: 调用API获取构建日志
    console.log('加载构建日志:', build.id)
    // 模拟日志数据
    buildLogs.value = [
      { content: 'Started by user developer1', level: 'INFO' },
      { content: 'Building in workspace /var/jenkins_home/workspace/frontend-build-dev', level: 'INFO' },
      { content: 'Cloning the remote Git repository', level: 'INFO' },
      { content: 'npm install', level: 'INFO' },
      { content: 'npm run build', level: 'INFO' },
      { content: 'Build completed successfully', level: 'INFO' }
    ]

    if (autoScroll.value) {
      await nextTick()
      if (logViewer.value) {
        logViewer.value.scrollTop = logViewer.value.scrollHeight
      }
    }
  } catch (error) {
    console.error('加载构建日志失败:', error)
  }
}

const loadProjects = async () => {
  try {
    // TODO: 调用API获取项目列表
    projects.value = [
      { id: 1, name: '电商系统' },
      { id: 2, name: 'CRM系统' }
    ]
  } catch (error) {
    console.error('加载项目列表失败:', error)
  }
}

const loadEnvironments = async () => {
  try {
    // TODO: 调用API获取环境列表
    environments.value = [
      { id: 1, name: '开发环境', code: 'dev' },
      { id: 2, name: '测试环境', code: 'test' },
      { id: 3, name: '预生产环境', code: 'uat' },
      { id: 4, name: '生产环境', code: 'prod' }
    ]
  } catch (error) {
    console.error('加载环境列表失败:', error)
  }
}

// 生命周期
onMounted(() => {
  loadBuilds()
  loadProjects()
  loadEnvironments()
})
</script>

<style scoped>
.jenkins-builds-audit-container {
  position: relative;
  min-height: 100vh;
  padding: 24px;
}

.starry-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  background-image:
    radial-gradient(2px 2px at 20px 30px, #eee, transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 90px 40px, #fff, transparent);
  z-index: -1;
}

.glass-container {
  background: rgba(164, 244, 186, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-title {
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.builds-filters {
  margin-bottom: 30px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 12px;
}

.toolbar-left {
  display: flex;
  gap: 12px;
  align-items: center;
}

.toolbar-right {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.search-group {
  min-width: 200px;
}

.filter-group {
  min-width: 140px;
}

.glass-input {
  background: rgba(164, 244, 186, 0.1);
  border: 1px solid rgba(164, 244, 186, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-size: 14px;
  transition: all 0.3s ease;
  width: 100%;
}

.glass-input:focus {
  outline: none;
  border-color: rgba(164, 244, 186, 0.5);
  background: rgba(164, 244, 186, 0.15);
}

.glass-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.glass-select {
  background: rgba(164, 244, 186, 0.1);
  border: 1px solid rgba(164, 244, 186, 0.3);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fff;
  font-size: 14px;
  transition: all 0.3s ease;
  width: 100%;
}

.glass-select:focus {
  outline: none;
  border-color: rgba(164, 244, 186, 0.5);
  background: rgba(164, 244, 186, 0.15);
}

.glass-select option {
  background: #2a5298;
  color: #fff;
}

.builds-table {
  background: rgba(164, 244, 186, 0.05);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}

.table-header {
  display: grid;
  grid-template-columns: 180px 200px 120px 150px 120px 100px 160px;
  background: rgba(164, 244, 186, 0.1);
  border-bottom: 1px solid rgba(164, 244, 186, 0.2);
}

.header-cell {
  padding: 16px 12px;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

.table-body {
  max-height: 600px;
  overflow-y: auto;
}

.table-row {
  display: grid;
  grid-template-columns: 180px 200px 120px 150px 120px 100px 160px;
  border-bottom: 1px solid rgba(164, 244, 186, 0.1);
  transition: all 0.3s ease;
}

.table-row:hover {
  background: rgba(164, 244, 186, 0.05);
}

.table-row.row-success {
  border-left: 3px solid #51cf66;
}

.table-row.row-failure {
  border-left: 3px solid #ff6b6b;
}

.table-row.row-unstable {
  border-left: 3px solid #ffd43b;
}

.table-row.row-aborted {
  border-left: 3px solid #868e96;
}

.table-row.row-building {
  border-left: 3px solid #339af0;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.7; }
  100% { opacity: 1; }
}

.table-cell {
  padding: 12px;
  display: flex;
  align-items: center;
}

.build-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.build-number {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: monospace;
}

.build-time {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}

.git-info {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.git-commit {
  background: rgba(164, 244, 186, 0.2);
  color: #a4f4ba;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 11px;
}

.git-branch {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.job-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.job-name {
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.job-server {
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
}

.job-type-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid;
  align-self: flex-start;
  margin-top: 2px;
}

.type-freestyle {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.3);
}

.type-maven {
  background: rgba(249, 115, 22, 0.2);
  color: #f97316;
  border-color: rgba(249, 115, 22, 0.3);
}

.type-pipeline {
  background: rgba(99, 102, 241, 0.2);
  color: #6366f1;
  border-color: rgba(99, 102, 241, 0.3);
}

.type-default {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
  border-color: rgba(156, 163, 175, 0.3);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.username {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}

.user-name {
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
}

.project-env-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-name {
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

.env-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid;
  align-self: flex-start;
}

.env-dev {
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.3);
}

.env-test {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.3);
}

.env-uat {
  background: rgba(168, 85, 247, 0.2);
  color: #a855f7;
  border-color: rgba(168, 85, 247, 0.3);
}

.env-prod {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.env-default {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
  border-color: rgba(156, 163, 175, 0.3);
}

.status-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-success {
  background: rgba(74, 222, 128, 0.2);
  color: #4ade80;
  border: 1px solid rgba(74, 222, 128, 0.3);
}

.status-failure {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.status-unstable {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.status-aborted {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
  border: 1px solid rgba(156, 163, 175, 0.3);
}

.status-building {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.status-unknown {
  background: rgba(156, 163, 175, 0.2);
  color: #9ca3af;
  border: 1px solid rgba(156, 163, 175, 0.3);
}

.duration-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.duration {
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}

.progress {
  width: 80px;
  height: 4px;
  background: rgba(164, 244, 186, 0.2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #a4f4ba, #4ade80);
  animation: progress 2s infinite;
}

@keyframes progress {
  0% { width: 0%; }
  50% { width: 70%; }
  100% { width: 100%; }
}

.action-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.glass-button {
  background: rgba(164, 244, 186, 0.2);
  border: 1px solid rgba(164, 244, 186, 0.3);
  border-radius: 8px;
  color: #fff;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.glass-button:hover {
  background: rgba(164, 244, 186, 0.3);
  border-color: rgba(164, 244, 186, 0.5);
  transform: translateY(-2px);
}

.glass-button.small {
  padding: 4px 8px;
  font-size: 12px;
}

.glass-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: rgba(255, 255, 255, 0.7);
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h3 {
  color: #fff;
  margin-bottom: 8px;
}

.empty-state p {
  margin-bottom: 24px;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
}

.pagination-info {
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
}

.log-modal {
  max-width: 1200px;
  max-height: 95vh;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h3 {
  color: #fff;
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.close-btn:hover {
  color: #fff;
}

.log-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.log-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.log-viewer {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 8px;
  padding: 16px;
  max-height: 500px;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
}

.log-line {
  display: flex;
  margin-bottom: 2px;
  font-size: 13px;
}

.line-number {
  color: rgba(255, 255, 255, 0.4);
  width: 50px;
  text-align: right;
  margin-right: 12px;
  user-select: none;
}

.line-content {
  color: rgba(255, 255, 255, 0.9);
  flex: 1;
  word-break: break-word;
}

.log-line.log-error .line-content {
  color: #ff6b6b;
}

.log-line.log-warn .line-content {
  color: #ffd43b;
}

.log-line.log-info .line-content {
  color: #51cf66;
}

.log-empty {
  text-align: center;
  padding: 40px;
  color: rgba(255, 255, 255, 0.6);
}

.build-detail-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.detail-section h4 {
  color: #fff;
  margin: 0 0 16px 0;
  font-size: 16px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-item .label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  font-weight: 500;
}

.detail-item .value {
  color: #fff;
  font-size: 14px;
}

.detail-json {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(164, 244, 186, 0.2);
  border-radius: 8px;
  padding: 16px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
</style>
